package com.java2001.swagger.controller;


import com.java2001.swagger.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"你好控制器"})
@Controller
public class HelloController {


    @ApiOperation(value = "hello路由", notes = "注意参数类型")
    @GetMapping(value = "/hello")
    public String hello() {
        return "hello";
    }


    //只要我们的接口中返回值中存在实体类，它就会被扫描到swagger
    @PostMapping(value = "/user")
    public User user() {
        return new User();
    }

    @ApiOperation(value = "hello2路由", notes = "注意参数类型")
    @GetMapping(value = "/hello2/{username}")
    public String hello2(@ApiParam(name = "username", value = "用户名", required = true)
                             @PathVariable("username") String username) {
        return "hello, " + username;
    }

    @ApiOperation(value = "postUser路由", notes = "注意参数类型")
    @PostMapping(value = "/postUser")
    @ResponseBody
    public User postUser(@ApiParam(name = "user", value = "User对象", required = true)
                         User user) {
        return user;
    }
}
